/*
 *	porc
 *  Property OR Callback
 *
 *	Internal handler for providing functionality that supports either
 *  selecting by property name, or using a callback function.
 *
 */
objx.requires("objx.each", "objx.corelist");

objx.porc = function(obj, sel, callback) {
	
	if (obj.type() != "array") {
		objx.error("objx.porc", "You can only use 'porc' on arrays.");
	}
	
	var selType = objx.type(sel);
	
	switch (selType) {
		case "string":	
		
			// property
			obj.each(function(item, index){
				callback.call(this, objx.get(item, sel), index, item);
			});
			
			break;
		case "function":
		
			// callback
			obj.each(function(item, index){
				callback.call(this, sel.apply(this, arguments), index, item);
			});
		
			break;
		default:
			objx.error("objx.porc does not know how to use objects of type " + selType + " to select items.  Use a string describing the property to select or a function that returns the value to use.");
			break;
	}
	
};

objx.fn.porc = function(sel, callback) {
	objx.porc(this, sel, callback);
	return this;
};

objx.provides("objx.corelist");